{literal}
<script>

$(document).ready(function()
    {

    var options2 = { 
            //target:        '#tariffs',   // target element(s) to be updated with server response 
           //beforeSubmit:  validate,  // pre-submit callback 
    		//page('','tarifflist');

                }; 


$('#tarif').submit(function() {
$(this).ajaxSubmit();
return false;
});

$('#tariff_add').submit(function() {
	$(this).ajaxSubmit(options2);
	
	return false;
	});
$("#save").click( function() {
$( this ).ajaxComplete(function(){

	page('','tarifflist');

	});
});
  });
function hide(id,type)
{

	if(type == 'si')
	{
if ($("#single" + id + ":first").attr("checked")) {
	$('#nmin' + id).attr("disabled", true);
	$('#dmin' + id).attr("disabled", true);
	$('#nhour' + id).attr("disabled", true);
	$('#dhour' + id).attr("disabled", true);
	$('#pricenight' + id).attr("disabled", true);
		  } else {

				$('#nmin' + id).attr("disabled", false);
				$('#dmin' + id).attr("disabled", false);
				$('#nhour' + id).attr("disabled", false);
				$('#dhour' + id).attr("disabled", false);
				$('#pricenight' + id).attr("disabled", false);
			  }
	}
	if (type == 'no')
	{

		if ($("#no" + id + ":first").attr("checked")) {
			$('#thr' + id).attr("disabled", true);
				  } else {
						$('#thr' + id).attr("disabled", false);
					  }

	}
}
function deltariff( name )
{
$.ajax({
type: "POST",
data: "tariff=" + name + "&del=1"  ,
url: "index.php?type=tarifflist"
});
   }


</script>
{/literal}
<form id="{if $smarty.get.tariff == 'new'}tariff_add{else}tarif{/if}" method="POST" action="/index.php?type=tariff&tariff={$smarty.get.tariff}">
<table>
{if $smarty.get.tariff == 'new'}

<tr>
<td>Назва тарифу</td><td><input  type="text" name="options[TARIFF]" value=""></td>
</tr>
{/if}
  <tr>
    <td>Абонплата</td><td><input size="2" type="text" name="options[Fee]" value="{$tariff.Fee}"></td>
    </tr>
    <tr>
    <td>Передплачений трафік</td><td><input size="2" type="text" name="options[Free]" value="{$tariff.Free}"></td>
    </tr>
    <tr>
    <td>Підрахунок трафіку</td><td><select name="options[TraffType]">
    <option {if $tariff.TraffType == "up"}selected{/if}>up</option><option{if $tariff.TraffType == "down"} selected{/if}>down</option><option {if $tariff.TraffType == "up+down"}selected{/if}>up+down</option><option {if $tariff.TraffType == "max"}selected{/if}>max</option></select>
    </td>
    </tr>
    <tr>
    <td>Вартість заморозки</td><td><input size="2" type="text" name="options[PassiveCost]" value="{$tariff.PassiveCost}"></td>
    </tr>
</table>


{foreach from=$tariff.dir item=dir}

<fieldset><legend><b>{$dir.name} </b></legend>
 
 <table>
<tr>
<td>Години</td><td>Хвилини</td>
</tr>
<tr>
<td>
<select id="dhour{$dir.num}" {if $tariff.SinglePrice[$dir.num] == 1}DISABLED="true"{/if} name="options[dhour][{$dir.num}]">
{section name=foo start=0 loop=24}
<option {if $tariff.Time[$dir.num].Dhour == $smarty.section.foo.index}SELECTED{/if}>
{if $smarty.section.foo.index < 10}0{/if}{$smarty.section.foo.index}
 </option>
{/section} 
 </select>
</td>
<td>
<select id="dmin{$dir.num}" {if $tariff.SinglePrice[$dir.num] == 1}DISABLED="true"{/if} name="options[dmin][{$dir.num}]">
{section name=foo start=0 loop=60}
<option {if $tariff.Time[$dir.num].Dmin == $smarty.section.foo.index}SELECTED{/if}>
{if $smarty.section.foo.index < 10}0{/if}{$smarty.section.foo.index}
 </option>
{/section} 
 </select>
 
<br>

</td>
<td>День</td>


<td><input size="3" type="text" name="options[PriceDay][{$dir.num}]" value="{if $tariff.PriceDayA[$dir.num] == $tariff.PriceDayB[$dir.num]}{$tariff.PriceDayA[$dir.num]}{else}{$tariff.PriceDayA[$dir.num]}/{$tariff.PriceDayB[$dir.num]}{/if}"></td>
<td>Ціна вдень</td>

<td><input id="thr{$dir.num}" {if $tariff.NoDiscount[$dir.num] == 1}DISABLED="true"{/if} size="3" type="text" name="options[Threshold][{$dir.num}]" value="{$tariff.Threshold[$dir.num]}">  Поріг (Мб)</td>
</tr>
<tr>
<td>
<select id="nhour{$dir.num}" {if $tariff.SinglePrice[$dir.num] == 1}DISABLED="true"{/if} name="options[nhour][{$dir.num}]">
{section name=foo start=0 loop=24}
<option  {if $tariff.Time[$dir.num].Nhour == $smarty.section.foo.index}SELECTED{/if}>
{if $smarty.section.foo.index < 10}0{/if}{$smarty.section.foo.index}
 </option>
{/section} 
 </select>
</td>
<td>
<select id="nmin{$dir.num}" {if $tariff.SinglePrice[$dir.num] == 1}DISABLED="true"{/if} name="options[nmin][{$dir.num}]">
{section name=foo start=0 loop=60}
<option {if $tariff.Time[$dir.num].Nmin == $smarty.section.foo.index}SELECTED{/if}>
{if $smarty.section.foo.index < 10}0{/if}{$smarty.section.foo.index}
 </option>
{/section} 
 </select>
 
</td>
<td>Ніч</td>
<td><input  READONLY id="pricenight{$dir.num}" {if $tariff.SinglePrice[$dir.num] == 1}DISABLED="true"{/if} size="3" type="text" name="options[PriceNight][{$dir.num}]" value="{if $tariff.PriceNightA[$dir.num] == $tariff.PriceNightB[$dir.num]}{$tariff.PriceNightA[$dir.num]}{else}{$tariff.PriceNightA[$dir.num]}/{$tariff.PriceNightB[$dir.num]}{/if}"></td>
<td>Ціна вночі</td>
<td><input id="no{$dir.num}" OnClick="hide({$dir.num},'no')" name="options[NoDiscount][{$dir.num}]" value="1" type="checkbox" {if $tariff.NoDiscount[$dir.num] == 1}CHECKED{/if}> Без порогу</td>
</tr>




</table>
 
 <input id="single{$dir.num}" OnClick="hide({$dir.num},'si')" name="options[SinglePrice][{$dir.num}]" type="checkbox" value="1" {if $tariff.SinglePrice[$dir.num] == 1}CHECKED{/if}> Ціна не залежить від часу

 
 </fieldset>
    
{/foreach}
{if $smarty.get.tariff == 'new'}
<input type="submit" id="save" name="save" value="Створити">
{else}
<input type="submit" name="save" OnClick="{literal}if(!confirm('Подумав?')) {return false;}{/literal}" value="Зберегти">
<input type="checkbox" name="del" OnClick="{literal}if(!confirm('Серйозно?')){return false;}{/literal}" value="1"> Видалити
{/if}
</form>